﻿using API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Web;


namespace API.Common
{
    public static class APICommon
    {
        private static DataLinqDataContext db = new DataLinqDataContext();
        public static string UserName;
        public static string Etoken;
        public static bool CheckEtoken(HttpRequestHeaders header)
        {
            UserName = string.Empty;
            Etoken = string.Empty;
            foreach(var d in header)
            {
               if(d.Key=="Etoken")
                   Etoken=d.Value.First();
                if(d.Key=="Username")
                    UserName = d.Value.First();

            }
            if (UserName != null && Etoken != null)
            {
                var checkExits = (from t in db.tbl_users
                                  where t.Username == UserName && t.Etoken == Etoken
                                 select t).FirstOrDefault();
                if(checkExits!=null)
                    return true;
            }
            return false;
        }
    }
}